Mendoza, 1993:
   IOI. 9 (Bussines). Se considera un numar de cel mult 100 companii. Fiecare din ele poate
detine procente din actiunile oricarei alte companii. Fiind date doua companii A si B, spunem ca A
controleaza compania B daca cel putin una din urmatoarele conditii este ndeplinita:
a) A=B;
b) A detine mai mult de 50% din B;
c) A controleaza k1 companii C(1),..,C(k), fiecare C(i) detine x(i)% din B si
x(1)+x(2)+..+x(k)>50.
    Se dau triplete {i,j,p} cu semnificatia: i detine p% din j. Se cer toate perechile (h,s) astfel
nct h controleaza compania s.
    Se cere sa se scrie un program care sa realizeze urmatoarele:
  1) Citeste dintr-un fisier de intrare lista tripletelor. Testele (seturile consecutive de date) sunt
separate ntre ele printr-o linie libera. Valorile i,j,p sunt numere naturale;
  2) Determina toate perechile (h,s) astfel nct h controleaza s;
  3) Scrie n fisierul text de iesire toate perechile (h,s) determinate la (2), cu hcs. Perechile
(h,s) trebuiesc scrise n ordinea crescatoare a lui h. Solutiile pentru seturi de date diferite vor fi separate
printr-o linie goala.
Exemplu: Pentru fisierul de intrare
2 3 25
1 4 36
4 5 63
2 1 48
3 4 30
4 2 52
5 3 30

1 2 30
2 3 52
3 4 51
4 5 70
5 4 20
4 3 20
fisierul de iesire trebuie sa aiba forma:
4 2
4 3
4 5

2 3
2 4
2 5
3 4
3 5
4 5
===============================================
Solutie (Vlad Atanasiu):

var grila:array[1..100,1..100] of byte;
    studiat:array[1..100,1..100] of boolean;
    input,output:text;
    i,j,nr,a,b,x:integer;
    repeta:boolean;
begin
assign(input,'input.io9');
assign(output,'output.io9');
reset(input);
rewrite(output);
while not eof(input) do
      begin
      nr:=0;
      for i:=1 to 100 do for j:=1 to 100 do grila[i,j]:=0;
      for i:=1 to nr do for j:=1 to nr do studiat[i,j]:=false;
      while (not eoln(input)) and (not eof(input)) do
            begin
            readln(input,a,b,x);
            inc(nr);
            grila[a,b]:=x;
            end;
      repeat
            repeta:=false;
            for i:=1 to nr do
                for j:=1 to nr do
                    if (i<>j) and (grila[i,j]>=50) and (not studiat[i,j]) then
                       begin
                       for x:=1 to nr do grila[i,x]:=grila[i,x]+grila[j,x];
                       studiat[i,j]:=true;
                       repeta:=true;
                       end;
      until not repeta;
      for i:=1 to nr do for j:=1 to nr do if (i<>j) and (grila[i,j]>=50) then writeln(output,i,' ',j);
      if eoln(input) then readln(input);
      writeln(output);
      end;
close(input);
close(output);
end.
============================================
Test intrare:
2 3 25
1 4 36
4 5 63
2 1 48
3 4 30
4 2 52
5 3 30

1 2 30
2 3 52
3 4 51
4 5 70
5 4 20
4 3 20
====================================
test iesire:
4 2
4 3
4 5

2 3
2 4
2 5
3 4
3 5
4 5
=========================================
